package com.ruoyi.web.users;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.users.vo.UMoneyVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.users.domain.UMoney;
import com.ruoyi.users.service.IUMoneyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户积分Controller
 *
 * @author yzc
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/users/money")
public class UMoneyController extends BaseController
{
    @Autowired
    private IUMoneyService uMoneyService;



    /**
     * 查询用户积分列表
     */
    @PreAuthorize("@ss.hasPermi('users:money:list')")
    @GetMapping("/list")
    public TableDataInfo list(UMoneyVo uMoneyVo)
    {
        startPage();
        System.err.println("aaaaaaaaaaaaaaa");
        //List<UMoney> list = uMoneyService.selectUMoneyList(uMoney);
        List<UMoneyVo> uMoneyVos =(uMoneyService.selectall(uMoneyVo));
//        UMoneyVo uMoneyVo = new UMoneyVo();
//        uMoneyVo.setUserName("aah");
//        uMoneyVo.setId(1L);
//        uMoneyVo.setuId(1L);
//        uMoneyVos.add(uMoneyVo);
        return getDataTable(uMoneyVos);
    }

    /**
     * 导出用户积分列表
     */
    @PreAuthorize("@ss.hasPermi('users:money:export')")
    @Log(title = "用户积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UMoney uMoney)
    {
        List<UMoney> list = uMoneyService.selectUMoneyList(uMoney);
        ExcelUtil<UMoney> util = new ExcelUtil<UMoney>(UMoney.class);
        util.exportExcel(response, list, "用户积分数据");
    }

    /**
     * 获取用户积分详细信息
     */
    @PreAuthorize("@ss.hasPermi('users:money:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(uMoneyService.selectUMoneyById(id));
    }

    /**
     * 新增用户积分
     */
    @PreAuthorize("@ss.hasPermi('users:money:add')")
    @Log(title = "用户积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UMoney uMoney)
    {
        return toAjax(uMoneyService.insertUMoney(uMoney));
    }

    /**
     * 修改用户积分
     */
    @PreAuthorize("@ss.hasPermi('users:money:edit')")
    @Log(title = "用户积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UMoney uMoney)
    {
        return toAjax(uMoneyService.updateUMoney(uMoney));
    }

    /**
     * 删除用户积分
     */
    @PreAuthorize("@ss.hasPermi('users:money:remove')")
    @Log(title = "用户积分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(uMoneyService.deleteUMoneyByIds(ids));
    }
}
